@use 'sass:map';

@use './shared' as *;
@use './design' as *;

// $types: primary info success warning error;

$linker: () !default;
$linker: map.merge(
  (
    color: inherit,
    color-hover: get-css-var('color-primary-light-1'),
    color-active: get-css-var('color-primary-dark-1'),
    color-disabled: get-css-var('content-color-disabled'),
    series-span: 8px,
    underline-height: 1px
  ),
  $linker
);

.#{$namespace}-linker {
  &-vars {
    @include define-preset-values('linker', $linker);
  }

  @mixin define-linker-style($style-map) {
    @include define-preset-style('linker', $style-map);
  }

  @include basis;

  position: relative;
  display: inline-flex;
  align-items: center;
  color: get-css-var('linker-color');
  text-decoration: none;
  vertical-align: inherit;
  cursor: pointer;
  outline: 0;
  transition: get-css-var('transition-color');

  & + & {
    margin-inline-start: get-css-var('linker-series-span');
  }

  &:hover,
  &:focus {
    color: get-css-var('linker-color-hover');
    text-decoration: none;
  }

  &:active {
    color: get-css-var('linker-color-active');
  }

  &--underline {
    &::after {
      position: absolute;
      right: 0;
      bottom: 0;
      inset-inline-start: 0;
      height: get-css-var('linker-underline-height');
      content: '';
      background-color: get-css-var('linker-color-hover');
      opacity: 0%;
      transition: get-css-var('transition-background'), get-css-var('transition-opacity');
    }

    &:hover::after {
      opacity: 100%;
    }

    &:active::after {
      background-color: get-css-var('linker-color-active');
    }
  }

  &--disabled {
    cursor: not-allowed;

    &,
    &:hover,
    &:focus,
    &:active {
      color: get-css-var('linker-color-disabled');
    }

    &:hover::after {
      opacity: 0%;
    }
  }

  &__icon {
    margin-inline-end: 3px;
  }

  @each $type in $types {
    &--#{$type} {
      @include define-linker-style(
        (
          color: 'color' $type 'base',
          color-hover: 'color' $type 'light-2',
          color-active: 'color' $type 'dark-1',
          color-disabled: 'color' $type 'opacity-5'
        )
      );
    }
  }
}
